package com.Controller;

import com.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController //不会被视图解析器即系,自动返回一个字符串
public class AjaxController {

    @RequestMapping("/t1")
    public String test() {
        return "hello";
    }

    @RequestMapping("/a11")
    public void a1(String name, HttpServletResponse response) throws IOException {
        System.out.println(name);
        if ("kuangsheng".equals(name)) {
            response.getWriter().print("true");
        } else {
            response.getWriter().print("false");
        }

    }

    @RequestMapping("/a2")
    public List<User> a2() {
        ArrayList<User> userList = new ArrayList<>();
        //添加数据
        userList.add(new User("java", 1, "男"));
        userList.add(new User("html", 18, "男"));
        userList.add(new User("python", 13, "男"));

        return userList;
    }

    @RequestMapping("/a3")
    public String a3(String name, String pwd) {
        String msg = "";
        if ("admin".equals(name)) {
            msg = "ok";
        } else {
            msg = "用户名有误";
        }
        if ("pwd".equals(name)) {
            msg = "ok";
        } else {
            msg = "密码有误";
        }
        return msg;
    }
    }




